<template>
    <el-container>
        <el-header>
            <h2>隔离室6666数据展示</h2>
        </el-header>
        <el-main>
            <el-row>
                <div style="width:700 ; height: 700; color:red; float: left;">
                    <el-card style="width: 700px; height: 350px; ">
                        <el-row>
                            <el-col :span="12">
                                <div class="grid-content bg-purple" style="text-align: left;">
                                    <h3>可调节气压器状态:{{ state7 }}</h3>
                                    <h3>病房内温度:{{ state8 }}℃</h3>
                                    <h3>病毒阈值1:{{ limit1 }}</h3>
                                    <h3>病毒阈值2:{{ limit2 }}</h3>
                                    <h3>调压风扇状态:{{ state5 }}</h3>
                                    <h3>调压风扇功率:{{ state6 }}</h3>
                                    <h3>警报灯状态:{{ warn }}</h3>
                                    <!-- <h3>阈值3:{{ limit3 }}℃</h3>
                                    <h3>风扇1功率:{{ power1 }}</h3>
                                    <h3>风扇2功率:{{ power2 }}</h3>
                                    <h3>LED灯发光强度:{{ power3 }}</h3> -->

                                </div>
                            </el-col>
                            <el-col :span="12">
                                <div class="grid-content bg-purple-light" style="text-align: left;">
                                    <h3>空调状态:{{ buttonvalue1 }}</h3>
                                    <h3>消毒室气压:{{ state1 }}Pa</h3>
                                    <h3>病房气压:{{ state2 }}Pa</h3>
                                    <h3>消毒室消毒状态:{{ state3 }}</h3>
                                    <h3>病房消毒状态:{{ state4 }}</h3>
                                 
                                  
                                

                                </div>
                            </el-col>
                        </el-row>



                    </el-card>

                </div>



                <div style="width: 700; height: 700; color:red; float: left; ">
                    <el-card style="width: 700px;height: 350px;">
                        <!-- <div>
                            <h3>当前时间:{{ currentTime }}</h3>
                        </div> -->
                        <el-row>
                            <el-col :span="12">
                                <div class="grid-content bg-purple" style="text-align: left;">
                                    <h3>病房病人:{{ card }}</h3>
                                    <h3>病房病人体温:{{ patient }}</h3>
                                    <h3>排队病人:{{ card1 }}</h3>
                                    <!-- <h3>排队温度:{{ pdpatient }}</h3> -->
                                    <h3>医生:{{ doctorflag }}</h3>
                                    
                                </div>
                            </el-col>
                            <el-col :span="12">
                                <div class="grid-content bg-purple-light" style="text-align: left;">
                                    <!-- <h3>阈值4:{{ limit4 }}</h3> -->
                                </div>
                            </el-col>
                        </el-row>
                    </el-card>


                </div>

            </el-row>
            <el-row>
                <div style="width: 300; height: 600; color:red; float: left; ">
                    <el-card style="width: 700px; height: 600px; ">
                        <el-row>
                            <el-col :span="12">
                                <div class="grid-content bg-purple" style="text-align: left;">

                                    <h3>控制空调</h3>
                                    <el-button type="primary" @click="setbuttonvalue1">制冷</el-button>
                                    <br>
                                    <el-button type="primary" @click="setbuttonvalue2">制热</el-button>
                                    <br>
                                    <el-button type="primary" @click="setbuttonvalue3">关闭</el-button>
                                    <br>
                                    <h3>门2</h3>
                                    <el-switch @change="setswitch3" v-model="switch3" active-color="#13ce66"
                                        inactive-color="#ff4949"></el-switch>
                                    <br>
                                    <h3>门1</h3>
                                    <el-switch @change="setswitch1" v-model="switch1" active-color="#13ce66"
                                        inactive-color="#ff4949"></el-switch>
                                    <h3>病房消毒装置</h3>
                                    <el-switch @change="setswitch2" v-model="switch2" active-color="#13ce66"
                                        inactive-color="#ff4949"></el-switch>
                                   
                                </div>
                            </el-col>
                            <el-col :span="12">
                                <div class="grid-content bg-purple-light" style="text-align: left;">
                                    <h3>设置病毒阈值1</h3>
                                    <el-input v-model="inputlimit1" placeholder="病毒阈值1"
                                        style="width: 90px;  "></el-input>
                                    <el-button type="primary" @click="setlimit1">确定</el-button>
                                    <h3>设置病毒阈值2</h3>
                                    <el-input v-model="inputlimit2" placeholder="病毒阈值2" style="width: 90px; "></el-input>
                                    <el-button type="primary" @click="setlimit2">确定</el-button>
                                    <br>
                                    <h3></h3>
                                    <el-button type="primary" @click="setbuttonvalue4">医生进来</el-button>
                                    <!-- <h3>设置光照强度阈值</h3>
                                    <el-input v-model="inputlimit3" placeholder="光照强度阈值"
                                        style="width: 90px; "></el-input>
                                    <el-button type="primary" @click="setlimit3">确定</el-button>
                                    <h3>设置风扇1功率</h3>
                                    <el-input v-model="inputpower1" placeholder="风扇1功率"
                                        style="width: 90px; "></el-input>
                                    <el-button type="primary" @click="setpower1">确定</el-button>
                                    <h3>设置风扇2功率</h3>
                                    <el-input v-model="inputpower2" placeholder="风扇2功率"
                                        style="width: 90px; "></el-input>
                                    <el-button type="primary" @click="setpower2">确定</el-button> -->
                                </div>
                            </el-col>
                        </el-row>
                    </el-card>
                </div>
                <div style="width: 700; height: 600;  float: left; ">
                    <el-card style="width: 700px; height: 600px;">
                        <el-row>
                            <el-col :span="12">
                                <div class="grid-content bg-purple" style="text-align: left;">
                                    <!-- <h3>设置LED灯功率</h3>
                                    <el-input v-model="inputpower3" placeholder="LED灯功率"
                                        style="width: 90px; "></el-input>
                                    <el-button type="primary" @click="setpower3">确定</el-button>
                                    <h3>设置可利用温差</h3>
                                    <el-input v-model="inputlimit4" placeholder="温度阈值1"
                                        style="width: 90px;  "></el-input>
                                    <el-button type="primary" @click="setlimit4">确定</el-button> -->
                                </div>
                            </el-col>
                            <el-col :span="12">
                                <div class="grid-content bg-purple-light" style="text-align: left;">
                            
                                </div>
                            </el-col>
                        </el-row>
                    </el-card>
                </div>

            </el-row>

        </el-main>
    </el-container>


</template>


<script>
const axios = require('axios');
import { websocket } from '@/utils/websocket';

//相当于导入和逻辑处理一起解决
var sendMeg = "";//处理发送给硬件的信息
var Meg = "";
var cardid = ""; // eslint-disable-line no-unused-vars

export default {
    mounted(){
        console.log(this.$pagechange);
    },
    data() {
        return {
            inputpower1:"",
            inputpower2:"",
            inputpower3:"",
            power1:0,
            power2:0,
            power3:0,
            inputlimit1: "",
            inputlimit2: "", 
            inputlimit3: "", 
            inputlimit4: "", 
            switch1: false,
            switch2: false,
            switch3: false, 
            switch4: false,
            card: [],  //病房内病人
            card1: [],  //排队病人
            state1: 0.9, 
            state2: 0.8, 
            state3: "关闭", 
            state4: "关闭", 
            state5: "关", 
            state6: 0, 
            state7: "", 
            state8: 26, 
            currentTime: "",
            limit1: 20, 
            limit2: 20,
            limit3: 25, 
            limit4: 20,
            buttonvalue1: "", //开始取号
            buttonvalue2: "", 
            buttonvalue3: "", 
            cardid: "", 
            obj:{},
            warn:"关",
            doctorflag:false,
            patient:[],
            patientt:"",
            pdpatient:[],
            tw1:0,
            tw2:0,
        }
    },
    computed: {
        globalVar() {   //全局变量
            return this.$store.state.globalVar;
        }
    },
    watch: {  //保存本地
        // state1(newValue) {
        //     console.log("保存成功")
        //   localStorage.setItem('state1', newValue);
        // },
        // card(newValue) {
        //   // 在这里执行保存到本地的操作，可以选择使用 localStorage 或其他方式
        //   localStorage.setItem('card', JSON.stringify(newValue));
        // }
    },
    created() {
        this.updateTime();
        this.initWecSocket();
        // this.state1 = localStorage.getItem('state1');  //监听事件可以保存这个变量的数据，而get事件可以从本地获取数据
        // this.card = JSON.parse(localStorage.getItem('card'));
    },
    computed: {   //全局变量实时响应,运用这个方法可以改变state这个变量的值
        globalVar() {
            return this.$store.state.globalVar;
        }
    },
    methods: {
        updateGlobalVar(newValue) {  //全局变量更新方法
            this.$store.commit('updateGlobalVar', newValue);
        },
        setpower3: function () { //设置LED灯功率
            this.power3 = this.inputpower3;
            if (this.power3 < 10) {
                sendMeg = "HWled100" + this.power3 + "Z";
            }
            else if (this.power3 < 100) {
                sendMeg = "HWled10" + this.power3 + "Z";
            }
            else {
                sendMeg = "HWled1" + this.power3 + "Z";
            }
            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
        },
        setpower2: function () { //设置风扇2功率
            this.power2 = this.inputpower2;
            this.switch2 = true;
            if (this.power2 < 10) {
                sendMeg = "HWfan200" + this.power2 + "Z";
            }
            else if (this.power2 < 100) {
                sendMeg = "HWfan20" + this.power2 + "Z";
            }
            else {
                sendMeg = "HWfan2" + this.power2 + "Z";
            }
            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
        },
        setpower1: function () { //设置风扇1功率
            this.power1 = this.inputpower1;
            this.switch1 = true;
            if (this.power1 < 10) {
                sendMeg = "HWfan100" + this.power1 + "Z";
            }
            else if (this.power1 < 100) {
                sendMeg = "HWfan10" + this.power1 + "Z";
            }
            else {
                sendMeg = "HWfan1" + this.power1 + "Z";
            }
            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
        },
        setlimit2: function () { //设置病毒阈值2
            this.limit2 = this.inputlimit2;
            // if (this.limit2 < 10) {
            //     sendMeg = "Lmax0" + this.limit2 + "Z";
            // } else {
            //     sendMeg = "Lmax" + this.limit2 + "Z";
            // }
            // axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            if (this.limit1 < 10 && this.limit2 < 10) {
                sendMeg = "Tmax0" + this.limit1 + "Lmax0" + this.limit2 + "Z";  //一条数据帧
            }
            else if (this.limit1 < 10 && this.limit2 >= 10) {
                sendMeg = "Tmax0" + this.limit1 + "Lmax" + this.limit2 + "Z";  
            }
            else if (this.limit2 < 10 && this.limit1 >= 10) {
                sendMeg = "Tmax" + this.limit1 + "Lmax0" + this.limit2 + "Z";  
            }
            else{
                sendMeg = "Tmax" + this.limit1 + "Lmax" + this.limit2 + "Z";  
            }
            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
        },
        setlimit1: function () {//设置病毒阈值1（位数固定要补零）
            this.limit1 = this.inputlimit1;
            // if (this.limit1 < 10) {
            //     sendMeg = "Tmax0" + this.limit1 + "Z";
            // } else {
            //     sendMeg = "Tmax" + this.limit1 + "Z";
            // }
            // console.log("修改成功！")
            // axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            if (this.limit1 < 10 && this.limit2 < 10) {
                sendMeg = "Tmax0" + this.limit1 + "Lmax0" + this.limit2 + "Z";  //一条数据帧
            }
            else if (this.limit1 < 10 && this.limit2 >= 10) {
                sendMeg = "Tmax0" + this.limit1 + "Lmax" + this.limit2 + "Z";  
            }
            else if (this.limit2 < 10 && this.limit1 >= 10) {
                sendMeg = "Tmax" + this.limit1 + "Lmax0" + this.limit2 + "Z";  
            }
            else{
                sendMeg = "Tmax" + this.limit1 + "Lmax" + this.limit2 + "Z";  
            }
            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
        },
        setswitch5: function () { //设置自动模式
            if (this.switch5 == true) {
                this.switch5 = true;
            }
            else {
                this.switch5 == false;
            }
        },
        setswitch3: function () { //设置空调开关/指示灯开关
            if (this.switch3 == true) {
                axios.get("http://localhost:8888/sendMessageTo/HWled1100Z");
            }
            else {
                axios.get("http://localhost:8888/sendMessageTo/HWled1000Z");
            }
        },
        setswitch2: function () { //设置病房消毒装置
            if (this.switch2 == true) {
                axios.get("http://localhost:8888/sendMessageTo/HWled4100Z");
                this.state4 = "消毒"
            }
            else {
                axios.get("http://localhost:8888/sendMessageTo/HWled4000Z");
                this.state4 = "关闭"
            }
        },
        setswitch1: function () { //设置门2开关
            if (this.switch1 == true) {
                axios.get("http://localhost:8888/sendMessageTo/HWled2100Z");
            }
            else {
                axios.get("http://localhost:8888/sendMessageTo/HWled2000Z");
            }
        },
        setbuttonvalue4: function () { //设置关闭
            this.doctorflag = true;
        },
        setbuttonvalue3: function () { //设置关闭
            this.buttonvalue1 = "关闭"
            axios.get("http://localhost:8888/sendMessageTo/HWled2sZ");
        },
        setbuttonvalue2: function () { //设置制热
            this.buttonvalue1 = "制热"
            axios.get("http://localhost:8888/sendMessageTo/HWled2rZ");
        },
        setbuttonvalue1: function () { //设置制冷
            // // 创建一个对象  //向后端发送数据并且存数据库
            // let obj = {};
            // obj['ysjid'] = '2021';
            // obj['stuid'] = '165165';
            // obj['ysl'] = '45';
            // obj['createTime'] = '15:23:10';

            // // 将对象转换为 JSON 格式
            // let jsonData = JSON.stringify(obj);

            // // 使用 axios 发送 POST 请求到后端接口，并指定请求头部信息
            // axios.post("http://localhost:8888/list/", jsonData, {
            //     headers: {
            //         'Content-Type': 'application/json'
            //     }
            // })
            //     .then(response => {
            //         // 请求成功时的处理
            //         console.log(response.data);
            //     })
            //     .catch(error => {
            //         // 请求失败时的处理
            //         console.error(error);
            //     });
            this.buttonvalue1 = "制冷"
            axios.get("http://localhost:8888/sendMessageTo/HWled2lZ");
        },
        reconnect: function () {
            if (this.limit1 < 10 && this.limit2 < 10) {
                sendMeg = "Tmax0" + this.limit1 + "Lmax0" + this.limit2 + "Z";  //一条数据帧
            }
            else if (this.limit1 < 10 && this.limit2 >= 10) {
                sendMeg = "Tmax0" + this.limit1 + "Lmax" + this.limit2 + "Z";  
            }
            else if (this.limit2 < 10 && this.limit1 >= 10) {
                sendMeg = "Tmax" + this.limit1 + "Lmax0" + this.limit2 + "Z";  
            }
            else{
                sendMeg = "Tmax" + this.limit1 + "Lmax" + this.limit2 + "Z";  
            }
            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            // sendMeg = "HWtime" + this.currentTime +  "Z";
            // axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            // clearInterval(this.timerId); //清除定时器
            //阈值数据帧分开发
            // sendMeg = "Tmax" + this.limit1 + "Z";
            // axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            // sendMeg = "Lmax" + this.limit2 + "Z";
            // axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            // sendMeg = "Light" + this.limit3 + "Z";
            // axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
            // if(this.overtime == 1){
            //     axios.get("http://localhost:8888/sendMessageTo/HWwarn1Z");
            //     this.overtime = 0; // 恢复原来的状态
            // }
        },
        updateTime: function () {  //获取当前时间
            this.currentTime = new Date().toLocaleTimeString();
            setTimeout(this.updateTime); // 每秒更新一次时间
        },
        initWecSocket: function () {
            // this.webSocket = new WebSocket("ws://localhost:8888//ws/WebSocket");
            this.webSocket = websocket;
            this.webSocket.onmessage = this.webSocketOnmessage;
            // this.webSocket.onerror = this.webSocketOnerror();
            //初始化完毕之后echarts显示数据信息
        },
        webSocketOnmessage: function (event) { //对接受的信息进行逻辑判断
            //    Meg=JSON.parse(event.data)
            Meg = event.data;
            console.log("收到硬件信息" + Meg);
            //根据收到的信息实时显示到页面
            if (event.data == "Reconnect") {
                this.reconnect()
            }
            else if (event.data == "开启定时") {  //定时装置
                this.timerId = setInterval(() => {
                    this.overtime = 1;
                    console.log("超时了！")
                }, 20000);
            }
            // else if (event.data.substring(0, 3) == "PID") {
            //     var s1 = event.data.substring(3,).split("PT");
            //     this.cardid = s1[0];
            //     this.patientt = s1[1];
            //     var flag = false;
            //     var flag1 = false; 
            //     var flag2 = false; 
            //     if (this.cardid == "A40B628A") {  //医生进来的时候
            //         this.doctorflag = true;
            //         let obj = {
            //                 people: '医生',
            //                 place: '进隔离室',
            //                 createTime: this.currentTime
            //             };
            //             axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj), {
            //                 headers: {
            //                     'Content-Type': 'application/json'
            //                 }
            //             });
            //     }
            //     else{
            //     if (this.card.length < 2) {  //当病房病人数量小于2时候
            //         if (this.doctorflag == true) {  //先判断医生是否已经进来
            //             // this.patient.shift(0);
            //             // this.card.shift(0);
            //             let obj1 = {  //医生进来后，如果后面刷的卡有和病房里的一样，就让病人出隔离室，并且存数据库
            //                 people: '患者' + this.cardid,
            //                 place: '出隔离室',
            //                 createTime: this.currentTime
            //             };
            //             axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj1), {
            //                 headers: {
            //                     'Content-Type': 'application/json'
            //                 }
            //             });
            //             let index = this.card.indexOf(this.cardid); //将刷到的对应病号移除
            //             if (index !== -1) {
            //                 this.card.splice(index, 1);
            //                 this.patient.splice(index, 1);   //相应温度也移除
            //                 this.doctorflag = false;
            //             }
            //             if (this.card1.length > 0) {  //同时让排队中的第一个自动入住
            //                 this.card.push(this.card1[0]);  //让排队中的第一个进来
            //                 this.card1.shift(0)   //将排队的第一个移除
            //                 this.patient.push(this.pdpatient[0]);   
            //                 this.pdpatient.shift(0);
            //                 flag2 = true;  
            //                 this.doctorflag = false;
            //             }
            //             let obj = {
            //                     people: '医生',
            //                     place: '出隔离室',
            //                     createTime: this.currentTime
            //                 };
            //                 axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj), {
            //                     headers: {
            //                         'Content-Type': 'application/json'
            //                     }
            //                 });
                        
            //         }else{
            //         for (var i = 0; i < this.card.length; i++) {  //判断是否有相同病号
            //             if (this.card[i] == this.cardid) { //如果有
            //                 flag1 = true;  // 标志位设为1
            //                 this.patient.shift(i);  //以下为更新新刷进来相同病号病人的温度，无关紧要
            //                 this.patient[i] = this.patientt
            //             }
            //         }
            //         if (flag1 == false) {  //如果没有相同的
            //             let obj = {  //将患者加进来并且存数据库
            //                 people: '患者' + this.cardid,
            //                 place: '进隔离室',
            //                 createTime: this.currentTime
            //             };
            //             axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj), {
            //                 headers: {
            //                     'Content-Type': 'application/json'
            //                 }
            //             });
            //             this.card.push(this.cardid);  //将病号加进来
            //             this.patient.push(this.patientt);  //同时将病号的温度加进来
                
            //         }  
            //     }
                
            //     }
            //     else if(this.card.length >= 2){  //病房如果已经住满人
            //         if (this.doctorflag == true) {  //先判断医生是否已经进来
            //             // this.patient.shift(0);
            //             // this.card.shift(0);
            //             let obj1 = {  //医生进来后，如果后面刷的卡有和病房里的一样，就让病人出隔离室，并且存数据库
            //                 people: '患者' + this.cardid,
            //                 place: '出隔离室',
            //                 createTime: this.currentTime
            //             };
            //             axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj1), {
            //                 headers: {
            //                     'Content-Type': 'application/json'
            //                 }
            //             });
            //             let index = this.card.indexOf(this.cardid); //将刷到的对应病号移除
            //             if (index !== -1) {
            //                 this.card.splice(index, 1);
            //                 this.patient.splice(index, 1);   //相应温度也移除
            //             }
            //             if (this.card1.length >= 1) {  //同时让排队中的第一个自动入住
            //                 this.card.push(this.card1[0]);  //让排队中的第一个进来
            //                 this.card1.shift(0)   //将排队的第一个移除
            //                 this.patient.push(this.pdpatient[0]);   
            //                 this.pdpatient.shift(0);
            //                 flag2 = true;  
            //                 this.doctorflag = false;

            //                 let obj = {
            //                     people: '医生',
            //                     place: '出隔离室',
            //                     createTime: this.currentTime
            //                 };
            //                 axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj), {
            //                     headers: {
            //                         'Content-Type': 'application/json'
            //                     }
            //                 });
            //             }
            //         }else{

            //         for (var i = 0; i < this.card.length; i++) {  
            //             if (this.card[i] == this.cardid) {
            //                 flag = true;
            //                 this.patient.shift(i);
            //                 this.patient[i] = this.patientt
            //             }
            //         } 
            //         if(flag == false  && flag2 == false){
            //             this.pdpatient.push(this.patientt);
            //             var samecard1flag = false;
            //             for(var i = 0; i < this.card1.length; i++){  //判断排队号是否有重复的
            //                 if(this.card1[i] == this.cardid){
            //                     samecard1flag = true;
            //                 }
            //             }
            //             if(samecard1flag == false){
            //                 this.card1.push(this.cardid);  
            //             }

            //         }else if(flag2 == true){
            //             flag2 = false;
            //         }    
            //     }     
            //      } 
            // }
            // }
            else if (event.data.substring(0, 3) == "PID") {
                var s1 = event.data.substring(3,).split("PT");
                this.cardid = s1[0];
                if (this.cardid == "A40B628A") { //医生进来标志一下
                    this.doctorflag = true;
                    let obj1 = {  //存数据库
                        people: '医生',
                        place: '进隔离室',
                        createTime: this.currentTime
                    };
                    axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj1), {
                        headers: {
                            'Content-Type': 'application/json'
                        }
                    });

                } else {
                    var samecardflag = false;  //相同病号标志位
                    var samecardoutflag = false;
                    for (var i = 0; i < this.card.length; i++) {
                        if (this.card[i] == this.cardid) {
                            samecardflag = true;
                            samecardoutflag = true;
                        }
                    }
                    for (var j = 0; j < this.card.length; j++) {
                        if (this.card1[j] == this.cardid) {
                            samecardflag = true;
                        }
                    }
                    if (samecardflag == false) {
                        if (this.card.length < 2) { //病房只能住两个人
                            this.card.push(this.cardid);
                            let obj1 = {  //存数据库
                                people: '患者' + this.cardid,
                                place: '进隔离室',
                                createTime: this.currentTime
                            };
                            axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj1), {
                                headers: {
                                    'Content-Type': 'application/json'
                                }
                            });
                            if (this.card.length == 1) {
                                sendMeg = "HWin" + this.cardid + "t" + this.tw1 + "Z";
                                axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
                            } else if (this.card.length == 2) {
                                sendMeg = "HWin" + this.cardid + "t" + this.tw2 + "Z";
                                axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
                            }
                        }
                        else if (this.card.length >= 2) {
                            this.card1.push(this.cardid);
                        }
                    }
                    if (samecardoutflag == true && this.doctorflag == true) {
                        let index = this.card.indexOf(this.cardid); //将刷到的对应病号移除
                        if (index !== -1) {
                            sendMeg = "HWout" + this.card[index] + "t" + this.patient[index] + "Z";
                            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
                            this.card.splice(index, 1);
                            this.patient.splice(index, 1);
                            this.doctorflag = false;
                            let obj1 = {  //存数据库
                                people: '患者' + this.cardid,
                                place: '出隔离室',
                                createTime: this.currentTime
                            };
                            axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj1), {
                                headers: {
                                    'Content-Type': 'application/json'
                                }
                            });

                        }
                        if (this.card1.length > 0) {
                            this.card.push(this.card1[0]);
                            if (this.card.length == 1) {
                                sendMeg = "HWin" + this.cardid + "t" + this.tw1 + "Z";
                            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
                        }else if(this.card.length == 2){
                            sendMeg = "HWin" + this.cardid + "t" + this.tw2 + "Z";
                            axios.get("http://localhost:8888/sendMessageTo/" + sendMeg);
                        }
                        let obj1 = {  //存数据库
                            people: '患者' + this.card1[0],
                            place: '进隔离室',
                            createTime: this.currentTime
                        };
                        axios.post("http://localhost:8888/inandoutlist/", JSON.stringify(obj1), {
                            headers: {
                                'Content-Type': 'application/json'
                            }
                        });
                        this.card1.shift(0);
                    }
                }
            }
            }
            else if (event.data.substring(0, 2) == "P1") {  
                this.state1 = event.data.substring(2,);
            }
            else if (event.data.substring(0, 2) == "P2") {  
                this.state2 = event.data.substring(2,);
            }
            else if (event.data.substring(0, 5) == "VIRUS") {  
                if(event.data.substring(5,) > this.limit1){
                    // alert("病毒含量超标！")
                }
            }
            else if (event.data.substring(0, 2) == "T#") {  
                this.state8 = event.data.substring(2,);
            }
            else if (event.data == "HWdian1Z") {  
                this.state7 = "加压"
            }
            else if (event.data == "HWdian2Z") {  
                this.state7 = "降压"
            }
            else if (event.data == "HWdian0Z") {  
                this.state7 = "关闭"
            }
            else if (event.data == "HWwarn1Z") {  
                this.warn = "开"
            }
            else if (event.data == "HWwarn0Z") {  
                this.warn = "关"
            }
            else if (event.data == "HWled2rZ") {  
                this.buttonvalue1 = "制热"
            }
            else if (event.data == "HWled2lZ") {  
                this.buttonvalue1 = "制冷"
            }
            else if (event.data == "HWled2sZ") {  
                this.buttonvalue1 = "关闭"
            }
            else if (event.data.substring(0, 3) == "T1#") {
                this.tw1 = event.data.substring(3,);
                if (this.card.length >= 1) {
                    this.$set(this.patient, 0, event.data.substring(3,));
                    // this.patient[0] == event.data.substring(3,);
                    sendMeg = this.card[0] + " " + event.data.substring(3,)
                    axios.get("http://localhost:8888/sendMessageToMyself/" + sendMeg);
                }
            }
            else if (event.data.substring(0, 3) == "T2#") {
                this.tw2 = event.data.substring(3,);
                if (this.card.length == 2) {
                    this.$set(this.patient, 1, event.data.substring(3,));
                    sendMeg = this.card[1] + " " + event.data.substring(3,)
                    axios.get("http://localhost:8888/sendMessageToMyself/" + sendMeg);
                }
            }
            else if (event.data.substring(0,6) == "HWled1") {  
                if(event.data.substring(6,event.data.length - 1) == "000"){
                    this.switch1 = false;
                }
                else{
                    this.switch1 =true;
                }
            }
            else if (event.data.substring(0,6) == "HWled2") {  
                if(event.data.substring(6,event.data.length - 1) == "000"){
                    this.switch3 = false;
                }
                else{
                    this.switch3 =true;
                }
            }
            else if (event.data.substring(0,6) == "HWled3") {  
                if(event.data.substring(6,event.data.length - 1) == "000"){
                    this.state3 = "关闭"
                }
                else {
                    this.state3 = "消毒"
                }
            }
            else if (event.data.substring(0, 6) == "HWled4") {
                if (event.data.substring(6, event.data.length - 1) == "000") {
                    this.switch2 = false;
                    this.state4 = "关闭"
                }
                else {
                    this.switch2 = true;
                    this.state4 = "消毒"
                }
            }
            else if (event.data.substring(0,6) == "HWfan3") {  
                if(event.data.substring(6,event.data.length - 1) == "000"){
                    this.state5 = "关"
                    this.state6 = 0
                }
                else{
                    this.state5 = "开"
                    this.state6 = Number(event.data.substring(6,event.data.length - 1));
                }
                
            }
            else if (event.data.substring(0, 4) == "Tmax") {
                this.limit1 = event.data.substring(4, event.data.length - 1) 
            }
            else if (event.data.substring(0, 4) == "Lmax") {
                this.limit1 = event.data.substring(4, event.data.length - 1) 
            }
            
           
            

        },

    }

}
</script>
